﻿using System;
using System.Text;
using System.Drawing;
using System.Collections.Generic;
using Un4seen.Bass;
using Un4seen.Bass.AddOn.Tags;


namespace Sirene.Core
{
    public class SireneData
    {
        private Dictionary<string, string> _tags = new Dictionary<string, string>();

        private string _fileName;
        private int _stream;
        private Image _imageCover;

        private double _elapsed;
        private double _total;
        private double _remain;

        private string _elapsedtime = string.Empty;
        private string _remaintime = string.Empty;


        public SireneData(string putFileName, int putStream)
        {
            _fileName = putFileName;
            _stream = putStream;
        }

        public Dictionary<string, string> GetTags
        {
            get { return _tags; }
            set { _tags = value; }
        }

        public Image GetImageCover
        {
            get { return _imageCover; }
            set { _imageCover = value; }
        }

        public string GetElapsedTime
        {
            get { return _elapsedtime; }
        }

        public string GetRemainingTime
        {
            get { return _remaintime; }
        }


        public void GetChannalInfo()
        {
            BASS_CHANNELINFO channalinfo = new BASS_CHANNELINFO();
            Bass.BASS_ChannelGetInfo(_stream, channalinfo);
        }

        public void GetTagsInfo()
        {
            TAG_INFO tagInfo = new TAG_INFO(_fileName);
            if (BassTags.BASS_TAG_GetFromFile(_stream, tagInfo))
            {
                _tags.Add("Album",tagInfo.album);
                _tags.Add("Artist", tagInfo.artist);
                _tags.Add("Title", tagInfo.title);
                _tags.Add("Comment",tagInfo.comment);
                _tags.Add("Genre",tagInfo.genre);
                _tags.Add("Year",tagInfo.year);
                _tags.Add("Track",tagInfo.track);
                _imageCover = tagInfo.PictureGetImage(0);
            }
        }

        public void GetStreamTiming()
        {
            long pos = Bass.BASS_ChannelGetPosition(_stream); // position in bytes
            long len = Bass.BASS_ChannelGetLength(_stream); // length in bytes

            _total = Bass.BASS_ChannelBytes2Seconds(_stream, len); // the total time length
            _elapsed = Bass.BASS_ChannelBytes2Seconds(_stream, pos); // the elapsed time length
            _remain = _total - _elapsed;

            _elapsedtime = String.Format(Utils.FixTimespan(_elapsed, "MMSS"));
            _remaintime = String.Format(Utils.FixTimespan(_remain, "MMSS"));
        }
    }
}
